import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;

import java.awt.Graphics;
import java.util.ArrayList;

import javax.swing.JPanel;

public class ViewPanel extends JPanel {
	//private ArrayList<ArrayList<Double>> data; // stock values
	private ArrayList<Graph> graphs=new ArrayList<Graph>();
	int minX, maxX = 365, minY = 0, maxY = 19000, xTick = 100, yTick = 1000; // window
																				// bounds,
																				// can
																				// be
																				// changed
																				// in
																				// realtime

	public ViewPanel(ArrayList<ArrayList<Double>> data) {
	//	this.data = data;
		for(ArrayList<Double> d:data){
			graphs.add(new Graph(d,this));
		}
		//zoomFit();
	}

	//private GeneralPath path = new GeneralPath();

	final static Font f = new Font(Font.SANS_SERIF, Font.PLAIN, 10);

	public void paintComponent(Graphics g2) {
		Graphics2D g = (Graphics2D) g2;
		g.setColor(Color.LIGHT_GRAY);
		g.fillRect(0, 0, 21, getHeight());
		g.setFont(f);
		g.fillRect(21, getHeight() - 20, getWidth() - 20, 20);
		g.setColor(Color.LIGHT_GRAY);
		for (int i = 0; i < (maxX - minX) / (float) xTick; i++) {
			g.setColor(Color.LIGHT_GRAY);
			g.drawLine(20 + i * xTick * (getWidth() - 20) / (maxX - minX),
					getHeight(), 20 + i * xTick * (getWidth() - 20)
							/ (maxX - minX), 0);
			g.setColor(Color.black);
			g.drawString("" + (xTick * i + minX), (25 + i * xTick
					* (getWidth() - 20) / (maxX - minX)), getHeight() - 5);

		}
		for (int i = 0; i < (maxY - minY) / (float) yTick; i++) {
			g.setColor(Color.LIGHT_GRAY);
			g.drawLine(0, getHeight()
					- (20 + i * yTick * (getHeight() - 20) / (maxY - minY)),
					getWidth(), getHeight()
							- (20 + i * yTick * (getHeight() - 20)
									/ (maxY - minY)));
			g.setColor(Color.BLACK);
			g.drawString("" + (yTick * i + minY), 0, getHeight()
					- (20 + i * yTick * (getHeight() - 20) / (maxY - minY))
					+ 10);
		}
		for(Graph graph:graphs){
			graph.draw(g2);
		}
		
	}
	/*
	public void zoomFit(){	//fits data so that all the y values in the x interval are shown
		double amt=0;
		//minY=Integer.MAX_VALUE;
		//maxY=Integer.MIN_VALUE;
		for (int i = minX;i<maxX; i++) {
			amt = data.get(i);
			System.out.println(amt);
			minY=(int) Math.min(amt, minY)-20;
			maxY=(int) Math.max(amt, maxY)+20;
			
		}
	}
	*/
}
